#ifndef _FACTORY_H_
#define _FACTORY_H_
template<class TBase>
class CreaterBase
{
public:
	virtual TBase* CreateNew()=0;
};
template<class TBase,class TClass>
class Creater :public CreaterBase<TBase>
{
public:
	virtual TBase* CreateNew()
	{
		return new TClass();
	}
};

template<class TBase>
class IDFactory
{
public:
	template<class TClass>
	void Register(uint32 iID)
	{
		CreaterBase<TBase> * pCreator=new Creater<TBase,TClass>();
		m_mCreators[iID]=pCreator;
	}
	TBase* Create(int32 iID)
	{
		std::map<int32,CreaterBase<TBase>*>::iterator it=m_mCreators.find(iID);
		if(it==m_mCreators.end()) return NULL;
		return it->second->CreateNew();
	}
private:
	std::map<int32,CreaterBase<TBase>*> m_mCreators;
};

#endif